package com.toby.blutooth;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    private BluetoothAdapter adapter;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Toast.makeText(MainActivity.this, "不支持此设备!!!", Toast.LENGTH_SHORT).show();
            finish();
        }
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
            BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
            adapter = manager.getAdapter();
        }
        if (adapter == null) {
            finish();
        }
        if (!adapter.isEnabled()) {
            adapter.enable();
        }
    }

    /**
     * 扫描设备
     *
     * @param enable true表示可扫描设备
     */
    private void scanDev(boolean enable) {
        if (enable) {
            adapter.startLeScan(mLeScanCallBack);
        }
    }

    private MyLeScanCallBack mLeScanCallBack = new MyLeScanCallBack();

    private class MyLeScanCallBack implements BluetoothAdapter.LeScanCallback {

        @Override
        public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {

        }
    }


}
